package cn.tedu;

//      --继承Thread类
//  		--好处: 方法多,创建对象的方式多
//  		--坏处: 强耦合,程序设计理念相对不灵活
//  	--实现Runnable接口
//  		--好处: 松耦合,方便程序设计.因为接口可以多继承多实现,还能继承时多实现
//  		--坏处: 方法少只有一个run(),也不能new

import sun.font.FontRunIterator;
//继承Thread类
public class Test2 {
    public static void main(String[] args) {
        MyThread t=new MyThread();//创建线程----新建状态
        //t.run();只是普通的方法的调用过程,根本不是多线程
        t.start();//开启线程---可运行状态
        //t.setName("郜");

        System.out.println();

        //再创建一个线程  模拟多线程
        MyThread t1=new MyThread();
        //t.run();
        t1.start();
        //t1.setName("晨");

        for (int i = 0; i <10 ; i++) {
            new MyThread().start();
        }
    }
}
class MyThread extends Thread{
    @Override
    public void run(){//运行状态
        for (int i = 0; i < 5; i++) {
            //System.out.println(new Thread().getName());//super.换成new Thread().就错了
            System.out.println(super.getName());//super. 可以省略,最后写上
        }
    }//终止状态
}
      //多线程
      /*Thread-0
        Thread-0
        Thread-0
        Thread-0
        Thread-0
        Thread-1
        Thread-2
        Thread-2
        Thread-2
        Thread-2
        Thread-2
        Thread-1
        Thread-3
        Thread-3
        Thread-3
        Thread-3
        Thread-3
        Thread-1
        Thread-1
        Thread-4
        Thread-4
        Thread-4
        Thread-4
        Thread-4
        Thread-1
        Thread-5
        Thread-5
        Thread-5
        Thread-5
        Thread-5
        Thread-6
        Thread-6
        Thread-6
        Thread-6
        Thread-6
        Thread-7
        Thread-7
        Thread-7
        Thread-7
        Thread-7
        Thread-9
        Thread-9
        Thread-9
        Thread-9
        Thread-9
        Thread-11
        Thread-11
        Thread-11
        Thread-11
        Thread-11
        Thread-8
        Thread-8
        Thread-8
        Thread-8
        Thread-8
        Thread-10
        Thread-10
        Thread-10
        Thread-10
        Thread-10*/
